<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Member extends CI_Controller {
	function __construct() {
    parent::__construct();	
		$this->isLogin();	
		$this->load->model('member_model');
	}
	
	function isLogin(){
		$login=$this->session->userdata('isLogin');
		if(! isset($login)||$login != true){
			$this->session->set_flashdata('error_login', 'Untuk Mengakses Admin Anda Harus Login!');
			redirect('login');	
		}
	}

	public function index(){
		$data['main_view']='admin/member/read';
		$data['hasil']=$this->member_model->read();
		$this->load->view('admin/template',$data);
	}
	
	function free(){
		$data['main_view']='admin/member/read';
		$data['status']='Free';
		$data['hasil']=$this->member_model->free();
		$this->load->view('admin/template',$data);
	}

	function premium(){
		$data['main_view']='admin/member/read';
		$data['status']='Premium';
		$data['hasil']=$this->member_model->premium();
		$this->load->view('admin/template',$data);
	}

	function permintaan_update(){
		$data['main_view']='admin/member/permintaan_update';
		$data['hasil']=$this->member_model->permintaan_update();
		$this->load->view('admin/template',$data);
	}
	
	function detail_free($id){
		$data['main_view']='admin/member/detail';
		$data['jenis']='free';
		$data['hasil']=$this->member_model->detail($id);
		$cek = array('status_cek' => "1");
		$this->member_model->update($id,$cek);
		$this->load->view('admin/template',$data);
	}

	function detail_premium($id){
		$data['main_view']='admin/member/detail';
		$data['jenis']='premium';
		$data['hasil']=$this->member_model->detail($id);
		$cek = array('status_cek' => "1");
		$this->member_model->update($id,$cek);
		$this->load->view('admin/template',$data);
	}

	function edit($id){
		$data['main_view']='admin/member/edit';
		$data['hasil']=$this->member_model->detail($id);
		$this->load->view('admin/template',$data);
	}
	
	function proses_update(){
		$id = $this->input->post('id');
		$data = array(
			'tgl_bayar' => tgl_insert($this->input->post('tanggal')),
			'status_bayar' => $this->input->post('status'),
			'status_member' => '2'
		);

		if($query=$this->member_model->update($id,$data)){
			redirect('member/permintaan_update');
		}
	}
	
	function delete_free($id){
		$this->member_model->delete($id);
		$this->session->set_flashdata('pesan', 'Data Sukses Dihapus');
		redirect('member/free');
	}

	function delete_premium($id){
		$this->member_model->delete($id);
		$this->session->set_flashdata('pesan', 'Data Sukses Dihapus');
		redirect('member/premium');
	}
}